package com.pureut.order.service.impl;

import com.pureut.order.domain.PublicMaterial;
import com.pureut.order.mapper.PublicMaterialMapper;
import com.pureut.order.service.PublicMaterialService;
import com.pureut.order.vo.MaterialMqVo;
import com.sale.common.redis.utils.RedisUtils;
import com.sale.common.satoken.utils.LoginHelper;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;

/**
 * 公共物料实现层
 */
@RequiredArgsConstructor
@Service
public class PublicMaterialServiceImpl implements PublicMaterialService {

    private final PublicMaterialMapper publicMaterialMapper;

    /**
     * 公共物料新增
     * @param mq
     */
    @Override
    public void insertPublicGoods(MaterialMqVo mq) {

        PublicMaterial publicMaterial = new PublicMaterial();
        BeanUtils.copyProperties(mq,publicMaterial);
        //获取用户id
        String tenantId = RedisUtils.getCacheObject(mq.getUserIdStr());
        publicMaterial.setTenantId(Long.parseLong(tenantId));
        publicMaterialMapper.insert(publicMaterial);
    }

    /**
     * 公共物料修改
     * @param mq
     */
    @Override
    public void updatePublicGoods(MaterialMqVo mq) {
        //根据物料编码获取数据
        publicMaterialMapper.updateData(mq);

    }

    /**
     * 公共物料删除
     * @param mq
     */
    @Override
    public void deletePublicGoods(MaterialMqVo mq) {
        List<String> idList = Arrays.asList(mq.getIdStr().split(","));
        publicMaterialMapper.deleteData(idList);

    }
}
